//
//  JEHManagementCollectionViewCell.m
//  SinaNews
//
//  Created by 蒋恩浩 on 15/12/7.
//  Copyright © 2015年 JEH. All rights reserved.
//

#import "JEHManagementCollectionViewCell.h"

@implementation JEHManagementCollectionViewCell

- (void)dealloc
{
    [_titleLabel retain];
    [_button retain];
    _delegate = nil;
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self nightMode];
        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        [_titleLabel retain];
        [_titleLabel nightMode];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.layer.borderWidth = 0.4;
        _titleLabel.layer.borderColor = [UIColor grayColor].CGColor;
        [self addSubview:self.titleLabel];
        
        self.button = [UIButton buttonWithType:UIButtonTypeCustom];
        [_button setImage:[UIImage imageNamed:@"delete"] forState:UIControlStateNormal];
        [_button addTarget:self action:@selector(deleteTitleAtItem:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_button];
    }
    return self;
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
    [super applyLayoutAttributes:layoutAttributes];
    self.titleLabel.frame = CGRectMake(0, 10, self.width - 10, self.height - 10);
    self.button.frame = CGRectMake(self.width - 20, 0, 20, 20);
}

- (void)setTemp:(NSInteger)temp {
    if (_temp != temp) {
        _temp = temp;
    }
}

- (void)deleteTitleAtItem:(UIButton *)sender {
    
    [self.delegate removeCellWithTemp:self.temp];
}

@end






















